import time
import re
import collections
import math
from qqwry import QQwry
from qqwry import updateQQwry

log_file1 = "D:/k12日志分析测试/newk12_center.log"

pattern_01 = r'''"(?P<remote_addr>[^"]+)" "(?P<remote_user>[^"]+)" "(?P<time_local>[^"]+)" "(?P<request>[^"]+)" "(?P<status>[^"]+)" "(?P<body_bytes_sent>[^"]+)" "(?P<bytes_sent>[^"]+)" "(?P<http_referer>[^"]+)" "(?P<http_user_agent>[^"]+)" "(?P<http_x_forwarded_for>[^"]+)" "(?P<http_host>[^"]+)" "(?P<request_time>[^"]+)" "(?P<upstream_response_time>[^"]+)" "(?P<upstream_addr>[^"]+)" "(?P<upstream_status>[^"]+)" "(?P<myuserid>[^"]+)"'''


def main():
    regex = re.compile(pattern_01)
    codes = set()
    with open(log_file1, 'r', encoding='utf-8') as f:
        for line in f:
            # 将每一行的日志转为字典
            mo = regex.search(line)
            if mo:
                code = mo.group('status')
                codes.add(code)
    print(codes)
    print(list(codes))
    print(sorted(list(codes)))  # 排序


# {'499', '302', '400', '301', '200', '206', '404', '304', '403'}
# ['499', '302', '400', '301', '200', '206', '404', '304', '403']
# ['200', '206', '301', '302', '304', '400', '403', '404', '499']

if __name__ == '__main__':
    main()
